package com.microsoft.socialphoto.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.microsoft.socialphoto.R;
import com.microsoft.socialphoto.adapter.item.PhotoItem;
import com.microsoft.socialphoto.utils.Utils;

public class LazyAdapter extends ArrayAdapter<Object> {

	private Activity activity;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;

	public LazyAdapter(Activity a, int textRes, List<Object> d) {

		super(a, textRes, d);

		activity = a;
		inflater = (LayoutInflater) a
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		imageLoader = new ImageLoader(activity.getApplicationContext());
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		final PhotoItem item = (PhotoItem) getItem(position);
		View vi = convertView;

		if (convertView == null)
			vi = inflater.inflate(R.layout.photo_item, null);

		ImageView image = (ImageView) vi.findViewById(R.id.image);
		imageLoader.DisplayImage(
				Utils.getThumbnailUrlFromFileName(item.getName()), activity,
				image);

		return vi;
	}
}